<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  
  <!-- ${tabComment} -->
<mapper namespace="com.java.mapper.${clazzName}Mapper" > 
	
	<resultMap id="BaseResultMap" type="com.java.bean.${clazzName}" >
	<#list columnList as mmap>
		<result column="${mmap.COLUMN_NAME?lower_case}" property="${mmap.COLUMN_NAME?lower_case}"/>
	</#list>
	</resultMap>
	       
	
	<sql id="Base_Column_List" >
		<#list columnList as mmap>${mmap.COLUMN_NAME?lower_case}<#if mmap_has_next>,</#if></#list>
	</sql>
	   
	<sql id="Example_Where_Clause">
	where 1=1
	<trim  suffixOverrides="," >
		<#list columnList as mmap>
		<if test="${mmap.COLUMN_NAME?lower_case} != null<#if mmap.DATA_TYPE=='VARCHAR' > and ${mmap.COLUMN_NAME?lower_case} != ''</#if>" >
		    and t.${mmap.COLUMN_NAME?lower_case} =  ${r"#{"}${mmap.COLUMN_NAME?lower_case}${r"}"}
		</if>
		</#list>
	</trim>
	</sql>
	 
	<select id="queryById"  resultMap="BaseResultMap" parameterType="Object">
		select <include refid="Base_Column_List" /> 
		 from ${tableName} t where t.id = ${r"#{id}"}
	</select>
	
	<select id="queryByCount" resultType="java.lang.Integer"  parameterType="Object">
		select count(1) from ${tableName} t
		<include refid="Example_Where_Clause"/>
	</select>
	
	<select id="queryByList" resultMap="BaseResultMap"  parameterType="Object">
		select <include refid="Base_Column_List" />
		from ${tableName} t
		
		<include refid="Example_Where_Clause"/>
	    <if test="pager.pageQueryCondition != null and pager.pageQueryCondition != ''" >
	        ${r"${pager.pageQueryCondition}"}
	    </if>
	    <if test="pager.orderCondition != null and pager.orderCondition != ''" >
	        ${r"${pager.orderCondition}"}
	    </if>
	</select>
	
	
	<insert id="add" parameterType="Object">
		<selectKey resultType="java.lang.Integer" order="BEFORE" keyProperty="id">
			SELECT PK_${tableName}.NEXTVAL from DUAL
		</selectKey>
		insert into
		${tableName} (<#list columnList as mmap>${mmap.COLUMN_NAME?lower_case}<#if mmap_has_next>,</#if></#list>)
		values(<#list columnList as mmap>${r"#{"}${mmap.COLUMN_NAME?lower_case},jdbcType=${mmap.DATA_TYPE}${r"}"}<#if mmap_has_next>,</#if></#list>)
	</insert>
	
	<update id="update" parameterType="Object">
		update ${tableName} set
		<#list columnList as mmap>${mmap.COLUMN_NAME?lower_case}=${r"#{"}${mmap.COLUMN_NAME?lower_case},jdbcType=${mmap.DATA_TYPE}${r"}"}<#if mmap_has_next>,</#if></#list>
		where id=${r"#{id}"}
	</update>
	
	<update id="updateBySelective" parameterType="Object">
		update ${tableName} set 1=1
		<trim suffixOverrides=",">
			<#list columnList as mmap>
			<if test="${mmap.COLUMN_NAME?lower_case} != null<#if mmap.DATA_TYPE=='VARCHAR' > and ${mmap.COLUMN_NAME?lower_case} != ''</#if>">
				${mmap.COLUMN_NAME?lower_case}= ${r"#{"}${mmap.COLUMN_NAME?lower_case}${r"}"},
			</if>
			</#list>
		</trim>
		where id=${r"#{id}"}
	</update>
	
	
	<delete id="delete" parameterType="Object">
		delete from ${tableName} where id = ${r"#{id}"}
	</delete>


</mapper>   
